import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

// Dio dio = Dio();
// Response response;
// response = await dio.get('');
// print(response.data.toString());

main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  MyApp({Key key}) : super(key: key);

  @override
  _MyApp createState() => new _MyApp();
}

class _MyApp extends State<MyApp> {
   Dio _dio = new Dio();
   String url;
  // get 无参数   _dio.get(url),  
  // get 有参数  _dio.get(url,queryParameters:map), 
  // post 有参数  _dio.post(url,data:map),  
  // 发起多个并发请求: Future.wait([dio.post("/info"),dio.get("/token")]); 
  // 下载文件 dio.download(url,_savePath);
  // 发送 FormData
  // FormData formData = new FormData.from({
  //    "name": "wendux",
  //    "age": 25,
  // });
  // response = await dio.post("/info", data: formData)
    Map<String, dynamic> map;
   @override 
  Widget build(BuildContext context){
    return new Container(
      alignment: Alignment.center,
      child: FutureBuilder(
          future: _dio.get(url), // get 无参数
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            //请求完成
            if (snapshot.connectionState == ConnectionState.done) {
              Response response = snapshot.data;
              //发生错误
              if (snapshot.hasError) {
                return Text(snapshot.error.toString());
              }
              //请求成功，通过项目信息构建用于显示项目名称的ListView
              return ListView(
                children: response.data.map<Widget>((e) =>
                    ListTile(title: Text(e["full_name"]))
                ).toList(),
              );
            }
            //请求未完成时弹出loading
            return CircularProgressIndicator();
          }
      ),
    );
  }
}
